package hij;
public class linkqueue implements queue{
    private node front;
    private node rear;
    
    public linkqueue(){
        this.front=this.rear=null;
    }
    
    public void clear(){
        this.front=this.rear=null;
    }
    
    public boolean isEmpty(){
        return this.front==null;
    }
    
    public Object getFront(){
        if(this.isEmpty()==true)
            throw new IllegalArgumentException("队已经为空");
        return this.front.data;
    }
    
    public void enQueue(Object o){
        node a=new node(o);
        if(this.front==null){
            a.next=this.front;
            this.front=this.rear=a;
        }
        else{
            node pos=this.rear;
            while(pos.next!=null)
                pos=pos.next;
            a.next=pos.next;
            pos.next=a;
        }
    }
    
    public Object deQueue(){
        if(this.isEmpty()==true)
            throw new IllegalArgumentException("队已经为空");
        node pos=this.front;
        front=front.next;
        rear=front;
        return  pos.data;
    }
}
